﻿//     Copyright (c) Microsoft Corporation.  All rights reserved.

using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Gateway.Utils;
using Newtonsoft.Json;

namespace Gateway.UpdateService.Models
{
    public class FilePackage 
    {
        public string PackageName { get; set; }
        public string Description { get; set; }

        /// <summary>
        /// List of files contained in this package relative to the storage account location
        /// </summary>
        [JsonConverter(typeof(StringToCollectionConverter))]
        public IList<string> StorageFileNames { get; set; }
        public bool ShouldSerializeStorageFileNames()
        {
            return false;
        }

        /// <summary>
        /// Projected list of files in this package. We flatten out the directory structure here as
        /// that is how it will be installed in the target.
        /// </summary>
        public IEnumerable<string> Files
        {
            get
            {
                if (this.StorageFileNames == null)
                {
                    return null;
                }
                return this.StorageFileNames
                    .Select(fileName => Path.GetFileName(fileName));
            }
        }
    }
}